﻿#region
/*******************************************************************************
** File Name:		    FoodSetRelationsService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodSetRelationsService : IFoodSetRelationsService
    {
		 IFoodSetRelations foodSetRelations = new FoodSetRelationsRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByFoodSetRelationsID (FoodSetRelationsModel model)
		{
			EFoodSetRelations entity = ConvertModelToEntity(model);

            foodSetRelations.UpdateByFoodSetRelationsID(entity);

		}

		public void DeleteByFoodSetRelationsID (System.Int64 foodSetRelationsID)
		{
		
            foodSetRelations.DeleteByFoodSetRelationsID(foodSetRelationsID);

		}
		 
        public FoodSetRelationsModel GetByFoodSetRelationsID (System.Int64 foodSetRelationsID)
        {
        
			EFoodSetRelations entity = foodSetRelations.GetByFoodSetRelationsID(foodSetRelationsID);
			
            FoodSetRelationsModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodSetRelationsModel> GetAll ()
		{
			IList<EFoodSetRelations> entity = foodSetRelations.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<FoodSetRelationsModel> list = new List<FoodSetRelationsModel>();

            foreach (var item in entity)
            {
                FoodSetRelationsModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private FoodSetRelationsModel ConvertEntityToModel(EFoodSetRelations entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodSetRelationsModel model = new FoodSetRelationsModel();
                        model.FoodSetRelationsID = entity.FoodSetRelationsID;
                        model.FoodSetID = entity.FoodSetID;
                        model.FoodInfoID = entity.FoodInfoID;
                        model.Count = entity.Count;
                        model.IsAdditional = entity.IsAdditional;
                        return model;
		}
		
		private EFoodSetRelations ConvertModelToEntity(FoodSetRelationsModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodSetRelations entity = new EFoodSetRelations();
                        entity.FoodSetRelationsID = model.FoodSetRelationsID;
                        entity.FoodSetID = model.FoodSetID;
                        entity.FoodInfoID = model.FoodInfoID;
                        entity.Count = model.Count;
                        entity.IsAdditional = model.IsAdditional;
                        return entity;
		}
		
		
		
		#endregion
    }
}